﻿<?php
require_once './lib.php';
header("Content-type:text/html;charset=utf-8");
$mysql = new DBAccess();

//将数据表查询的最新一期期号放入数组
$arr = array();

//重庆时时彩最新期号
$sql = "select qishu,ball_1,ball_2,ball_3,ball_4,ball_5 from lottery_result_cq WHERE state = 0 ORDER by id DESC  limit 1";
$result = $mysql->getRow($sql);
$arr['CQ'] = $result;

//北京PK拾最新期号
$sql = "select qishu,ball_1,ball_2,ball_3,ball_4,ball_5,ball_6,ball_7,ball_8,ball_9,ball_10 from lottery_result_bjpk WHERE state = 0 ORDER by id DESC  limit 1";
$result = $mysql->getRow($sql);
$arr['BJPK'] = $result;

//排列3最新期号
$sql = "select qishu,ball_1,ball_2,ball_3 from lottery_result_p3 WHERE state = 0 ORDER by id DESC  limit 1";
$result = $mysql->getRow($sql);
$arr['P3'] = $result;

//福彩3D最新期号
$sql = "select qishu,ball_1,ball_2,ball_3 from lottery_result_d3 WHERE state = 0 ORDER by id DESC  limit 1";
$result = $mysql->getRow($sql);
$arr['D3'] = $result;

//广东11选5最新期号
$sql = "select qishu,ball_1,ball_2,ball_3,ball_4,ball_5 from lottery_result_gd11 WHERE state = 0 ORDER by id DESC  limit 1";
$result = $mysql->getRow($sql);
$arr['GD11'] = $result;

//天津时时彩最新期号
$sql = "select qishu,ball_1,ball_2,ball_3,ball_4,ball_5 from lottery_result_tj WHERE state = 0 ORDER by id DESC  limit 1";
$result = $mysql->getRow($sql);
$arr['TJ'] = $result;


//定义相关数组
$dx = array('大', '小');
$ds = array('单', '双');
$lh = array('龙', '虎', '和');
$num = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',);

//存在重庆时时彩最新一期未结算
if (!empty($arr['CQ'])) {
    //对开奖结果进行换算规则
    $niuniu = b5_niuniu($arr['CQ']['ball_1'], $arr['CQ']['ball_2'], $arr['CQ']['ball_3'], $arr['CQ']['ball_4'], $arr['CQ']['ball_5']);
    $qishu_cq = $arr['CQ']['qishu'];
    //$hm存放球号
    $hm[] = $arr['CQ']['ball_1'];//第一个球
    $hm[] = $arr['CQ']['ball_2'];//第二个球
    $hm[] = $arr['CQ']['ball_3'];//第三个球
    $hm[] = $arr['CQ']['ball_4'];//第四个球
    $hm[] = $arr['CQ']['ball_5'];//第五个球
    //$hms存放规则
    $hms['zhs'][] = Ssc_Auto($hm, 1);//算总和
    $hms['zh'][] = Ssc_Auto($hm, 2);//算总和大小
    $hms['zh'][] = Ssc_Auto($hm, 3);//算总和单双
    $hms['zh'][] = Ssc_Auto($hm, 4);//算龙虎和
    $hms['three'][] = Ssc_Auto($hm, 5);//算前三
    $hms['three'][] = Ssc_Auto($hm, 6);//算中三
    $hms['three'][] = Ssc_Auto($hm, 7);//算后三
    $hms['niuniu'][] = $niuniu;//牛牛
    $hms['niuniu'][] = b5_niuds($niuniu);//牛大
    $hms['niuniu'][] = b5_niudx($niuniu);//牛小
    $sql = "select order_num,order_sub_num,quick_type,number,win,status,is_win from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number=$qishu_cq AND Gtype='CQ') AND status=0";
    $res = $mysql->getRows($sql);
    //定义数组存放对应彩种的子订单
    $arr1 = array();
    //定义数组存放对应的开奖结果
    $zjresultall = array();

    foreach ($res as $k => $v) {
        $arr1[] = $v['order_sub_num'];
        if ($v['quick_type'] == "第一球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm[0]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第二球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm[1]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第三球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm[2]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第四球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm[3]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第五球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm[4]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "总和龙虎和") {
            if (in_array($v['number'], $hms['zh'])) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "前三") {
            if ($v['number'] == $hms['three'][0]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "中三") {
            if ($v['number'] == $hms['three'][1]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "后三") {
            if ($v['number'] == $hms['three'][2]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "牛牛") {
            if (in_array($v['number'], $hms['niuniu'])) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
    }
//函数移除数组中的重复的值，并返回结果数组,再拼接成字符串
    $arr2 = implode(',', array_unique($arr1));

//判断中奖数组存在且不为空的时候
    if (isset($zjresultall) && !empty($zjresultall)) {

        foreach ($zjresultall as $k => $v) {
            $win = 0.0;
            $set = array('is_win' => 1, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "order_num='$v[order_num]' AND order_sub_num='$v[order_sub_num]'");
            $win = (float)$v['win'];

            $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
            $mysql->query($sql_money);
        }
    }
//将子订单表中状态未结算修改为正常
    $sql = "update order_lottery_sub set status='1',is_win='0' WHERE status='0'AND order_sub_num IN ($arr2)";
    $mysql->query($sql);

//将总订单表中状态未结算修改为正常
    $sql = "update order_lottery set status='1' WHERE status='0' AND lottery_number=$qishu_cq";
    $mysql->query($sql);

//将时时彩结果表状态修改为正常
    $sql = "update lottery_result_cq set state='1' WHERE state='0' AND qishu=$qishu_cq";
    $mysql->query($sql);

}
//存在北京PK拾最新一期未结算
if (!empty($arr['BJPK'])) {//北京PK
    $qishu_bjpk = $arr['BJPK']['qishu'];
    $hm1[] = $arr['BJPK']['ball_1'];
    $hm1[] = $arr['BJPK']['ball_2'];
    $hm1[] = $arr['BJPK']['ball_3'];
    $hm1[] = $arr['BJPK']['ball_4'];
    $hm1[] = $arr['BJPK']['ball_5'];
    $hm1[] = $arr['BJPK']['ball_6'];
    $hm1[] = $arr['BJPK']['ball_7'];
    $hm1[] = $arr['BJPK']['ball_8'];
    $hm1[] = $arr['BJPK']['ball_9'];
    $hm1[] = $arr['BJPK']['ball_10'];
    $hms1[] = Pk10_Auto_quick($hm1, 1);
    $hms1[] = Pk10_Auto_quick($hm1, 2);
    $hms1[] = Pk10_Auto_quick($hm1, 3);
    $hms1[] = Pk10_Auto_quick($hm1, 4);
    $hms1[] = Pk10_Auto_quick($hm1, 5);
    $hms1[] = Pk10_Auto_quick($hm1, 6);
    $hms1[] = Pk10_Auto_quick($hm1, 7);
    $hms1[] = Pk10_Auto_quick($hm1, 8);

    $sql = "select order_num,order_sub_num,quick_type,number,win,status,is_win from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number=$qishu_bjpk AND Gtype='BJPK') AND status=0";
    $res1 = $mysql->getRows($sql);

    //定义数组存放对应彩种的子订单
    $arr1 = array();
    //定义数组存放对应的开奖结果
    $zjresultall = array();

    foreach ($res1 as $k => $v) {
        $arr1[] = $v['order_sub_num'];
        if ($v['quick_type'] == "冠亚军和") {
            if ($v['number'] == $hms1[0]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == $hms1[1]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == $hms1[2]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "冠军") {
            if ($v['number'] == $hm1[0]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $lh)) {
                if ($v['number'] == $hms1[3]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "亚军") {
            if ($v['number'] == $hm1[1]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $lh)) {
                if ($v['number'] == $hms1[4]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第三名") {
            if ($v['number'] == $hm1[2]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $lh)) {
                if ($v['number'] == $hms1[5]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第四名") {
            if ($v['number'] == $hm1[3]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $lh)) {
                if ($v['number'] == $hms1[6]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第五名") {
            if ($v['number'] == $hm1[4]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $lh)) {
                if ($v['number'] == $hms1[7]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第六名") {
            if ($v['number'] == $hm1[5]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[5])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[5])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第七名") {
            if ($v['number'] == $hm1[6]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[6])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[6])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第八名") {
            if ($v['number'] == $hm1[7]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[7])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[7])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第九名") {
            if ($v['number'] == $hm1[8]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[8])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[8])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第十名") {
            if ($v['number'] == $hm1[9]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Pk10_Auto($hm1, 9, $hm1[9])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Pk10_Auto($hm1, 10, $hm1[9])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }

    }
    //函数移除数组中的重复的值，并返回结果数组,再拼接成字符串
    $arr2 = implode(',', array_unique($arr1));

    //判断中奖数组存在且不为空的时候
    if (isset($zjresultall) && !empty($zjresultall)) {

        foreach ($zjresultall as $k => $v) {
            $win = 0.0;
            $set = array('is_win' => 1, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "order_num='$v[order_num]' AND order_sub_num='$v[order_sub_num]'");
            $win = (float)$v['win'];

            $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
            $mysql->query($sql_money);
        }
    }
    //将子订单表中状态未结算修改为正常
    $sql = "update order_lottery_sub set status='1',is_win='0' WHERE status='0'AND order_sub_num IN ($arr2)";
    $mysql->query($sql);

    //将总订单表中状态未结算修改为正常
    $sql = "update order_lottery set status='1' WHERE status='0' AND lottery_number=$qishu_bjpk";
    $mysql->query($sql);

    //将北京PK结果表状态修改为正常
    $sql = "update lottery_result_bjpk set state='1' WHERE state='0' AND qishu=$qishu_bjpk";
    $mysql->query($sql);

}
//存在排列3最新一期未结算
if (!empty($arr['P3'])) {//排列3
    $qishu_p3 = $arr['P3']['qishu'];
    $hm2[] = $arr['P3']['ball_1'];
    $hm2[] = $arr['P3']['ball_2'];
    $hm2[] = $arr['P3']['ball_3'];
    $hms2[] = f3D_Auto($hm2, 1);
    $hms2[] = f3D_Auto($hm2, 2);
    $hms2[] = f3D_Auto($hm2, 3);
    $hms2[] = f3D_Auto($hm2, 4);
    $hms2[] = f3D_Auto($hm2, 5);
    $hms2[] = f3D_Auto($hm2, 6);


    $sql = "select order_num,order_sub_num,quick_type,number,win,status,is_win from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number=$qishu_p3 AND Gtype='P3') AND status=0";
    $res2 = $mysql->getRows($sql);

    //定义数组存放对应彩种的子订单
    $arr1 = array();
    //定义数组存放对应的开奖结果
    $zjresultall = array();

    foreach ($res2 as $k => $v) {
        $arr1[] = $v['order_sub_num'];
        if ($v['quick_type'] == "第一球") {
            if ($v['number'] == $hm2[0]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm2[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm2[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第二球") {
            if ($v['number'] == $hm2[1]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm2[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm2[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第三球") {
            if ($v['number'] == $hm2[2]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm2[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm2[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "总和龙虎和") {
            if (in_array($v['number'], array($hms2[1], $hms2[2], $hms2[3]))) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "三连") {
            if ($v['number'] == $hms2['4']) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "跨度") {
            if ($v['number'] == $hms2['5']) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
    }
    //函数移除数组中的重复的值，并返回结果数组,再拼接成字符串
    $arr2 = implode(',', array_unique($arr1));

    //判断中奖数组存在且不为空的时候
    if (isset($zjresultall) && !empty($zjresultall)) {

        foreach ($zjresultall as $k => $v) {
            $win = 0.0;
            $set = array('is_win' => 1, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "order_num='$v[order_num]' AND order_sub_num='$v[order_sub_num]'");
            $win = (float)$v['win'];

            $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
            $mysql->query($sql_money);
        }
    }
    //将子订单表中状态未结算修改为正常
    $sql = "update order_lottery_sub set status='1',is_win='0' WHERE status='0'AND order_sub_num IN ($arr2)";
    $mysql->query($sql);

    //将总订单表中状态未结算修改为正常
    $sql = "update order_lottery set status='1' WHERE status='0' AND lottery_number=$qishu_p3";
    $mysql->query($sql);

    //将排列3结果表状态修改为正常
    $sql = "update lottery_result_p3 set state='1' WHERE state='0' AND qishu=$qishu_p3";
    $mysql->query($sql);
}
//存在福彩3D最新一期未结算
if (!empty($arr['D3'])) {//福彩3D
    $qishu_d3 = $arr['D3']['qishu'];
    $hm3[] = $arr['D3']['ball_1'];
    $hm3[] = $arr['D3']['ball_2'];
    $hm3[] = $arr['D3']['ball_3'];
    $hms3[] = f3D_Auto($hm3, 1);
    $hms3[] = f3D_Auto($hm3, 2);
    $hms3[] = f3D_Auto($hm3, 3);
    $hms3[] = f3D_Auto($hm3, 4);
    $hms3[] = f3D_Auto($hm3, 5);
    $hms3[] = f3D_Auto($hm3, 6);


    $sql = "select order_num,order_sub_num,quick_type,number,win,status,is_win from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number=$qishu_d3 AND Gtype='D3') AND status=0";
    $res3 = $mysql->getRows($sql);

    //定义数组存放对应彩种的子订单
    $arr1 = array();
    //定义数组存放对应的开奖结果
    $zjresultall = array();

    foreach ($res3 as $k => $v) {
        $arr1[] = $v['order_sub_num'];
        if ($v['quick_type'] == "第一球") {
            if ($v['number'] == $hm3[0]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm3[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm3[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第二球") {
            if ($v['number'] == $hm3[1]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm3[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm3[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第三球") {
            if ($v['number'] == $hm3[2]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            } elseif (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm3[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            } elseif (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm3[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "总和龙虎和") {
            if (in_array($v['number'], array($hms3[1], $hms3[2], $hms3[3]))) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "三连") {
            if ($v['number'] == $hms3['4']) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "跨度") {
            if ($v['number'] == $hms3['5']) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
    }
    //函数移除数组中的重复的值，并返回结果数组,再拼接成字符串
    $arr2 = implode(',', array_unique($arr1));

    //判断中奖数组存在且不为空的时候
    if (isset($zjresultall) && !empty($zjresultall)) {

        foreach ($zjresultall as $k => $v) {
            $win = 0.0;
            $set = array('is_win' => 1, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "order_num='$v[order_num]' AND order_sub_num='$v[order_sub_num]'");
            $win = (float)$v['win'];

            $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
            $mysql->query($sql_money);
        }
    }
    //将子订单表中状态未结算修改为正常
    $sql = "update order_lottery_sub set status='1',is_win='0' WHERE status='0'AND order_sub_num IN ($arr2)";
    $mysql->query($sql);

    //将总订单表中状态未结算修改为正常
    $sql = "update order_lottery set status='1' WHERE status='0' AND lottery_number=$qishu_d3";
    $mysql->query($sql);

    //将福彩3D结果表状态修改为正常
    $sql = "update lottery_result_d3 set state='1' WHERE state='0' AND qishu=$qishu_d3";
    $mysql->query($sql);


}
//存在广东11选5最新一期未结算
if (!empty($arr['GD11'])) {//广东11选5
    $qishu_gd11 = $arr['GD11']['qishu'];
    $hm4[] = $arr['GD11']['ball_1'];
    $hm4[] = $arr['GD11']['ball_2'];
    $hm4[] = $arr['GD11']['ball_3'];
    $hm4[] = $arr['GD11']['ball_4'];
    $hm4[] = $arr['GD11']['ball_5'];
    $hms4[] = gd11x5_Auto($hm4, 1);
    $hms4[] = gd11x5_Auto($hm4, 2);
    $hms4[] = gd11x5_Auto($hm4, 3);
    $hms4[] = gd11x5_Auto($hm4, 4);
    $hms4[] = gd11x5_Auto($hm4, 5);
    $hms4[] = gd11x5_Auto($hm4, 6);
    $hms4[] = gd11x5_Auto($hm4, 7);


    $sql = "select order_num,order_sub_num,quick_type,number,win,status,is_win from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number=$qishu_gd11 AND Gtype='GD11') AND status=0";
    $res4 = $mysql->getRows($sql);

    //定义数组存放对应彩种的子订单
    $arr1 = array();
    //定义数组存放对应的开奖结果
    $zjresultall = array();

    foreach ($res4 as $k => $v) {
        $arr1[] = $v['order_sub_num'];
        if ($v['quick_type'] == "第一球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm4[0]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == gd11x5_Dx($hm4[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == gd11x5_Ds($hm4[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第二球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm4[1]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == gd11x5_Dx($hm4[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == gd11x5_Ds($hm4[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第三球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm4[2]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == gd11x5_Dx($hm4[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == gd11x5_Ds($hm4[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第四球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm4[3]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == gd11x5_Dx($hm4[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == gd11x5_Ds($hm4[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第五球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm4[4]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == gd11x5_Dx($hm4[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == gd11x5_Ds($hm4[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "总和龙虎和") {
            if (in_array($v['number'], array($hms4[1], $hms4[2], $hms4[3]))) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "前三") {
            if ($v['number'] == $hms4[4]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "中三") {
            if ($v['number'] == $hms4[5]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "后三") {
            if ($v['number'] == $hms4[6]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
    }
    //函数移除数组中的重复的值，并返回结果数组,再拼接成字符串
    $arr2 = implode(',', array_unique($arr1));

    //判断中奖数组存在且不为空的时候
    if (isset($zjresultall) && !empty($zjresultall)) {

        foreach ($zjresultall as $k => $v) {
            $win = 0.0;
            $set = array('is_win' => 1, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "order_num='$v[order_num]' AND order_sub_num='$v[order_sub_num]'");
            $win = (float)$v['win'];

            $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
            $mysql->query($sql_money);
        }
    }
    //将子订单表中状态未结算修改为正常
    $sql = "update order_lottery_sub set status='1',is_win='0' WHERE status='0'AND order_sub_num IN ($arr2)";
    $mysql->query($sql);

    //将总订单表中状态未结算修改为正常
    $sql = "update order_lottery set status='1' WHERE status='0' AND lottery_number=$qishu_gd11";
    $mysql->query($sql);

    //将广东11选5结果表状态修改为正常
    $sql = "update lottery_result_gd11 set state='1' WHERE state='0' AND qishu=$qishu_gd11";
    $mysql->query($sql);
}
//存在天津时时彩最新一期未结算
if (!empty($arr['TJ'])) {//天津时时彩
    //对开奖结果进行换算规则
    $niuniu1 = b5_niuniu($arr['TJ']['ball_1'], $arr['TJ']['ball_2'], $arr['TJ']['ball_3'], $arr['TJ']['ball_4'], $arr['TJ']['ball_5']);
    $qishu_tj = $arr['TJ']['qishu'];
    //$hm存放球号
    $hm5[] = $arr['TJ']['ball_1'];//第一个球
    $hm5[] = $arr['TJ']['ball_2'];//第二个球
    $hm5[] = $arr['TJ']['ball_3'];//第三个球
    $hm5[] = $arr['TJ']['ball_4'];//第四个球
    $hm5[] = $arr['TJ']['ball_5'];//第五个球
    //$hms存放规则
    $hms5['zhs'][] = Ssc_Auto($hm5, 1);//算总和
    $hms5['zh'][] = Ssc_Auto($hm5, 2);//算总和大小
    $hms5['zh'][] = Ssc_Auto($hm5, 3);//算总和单双
    $hms5['zh'][] = Ssc_Auto($hm5, 4);//算龙虎和
    $hms5['three'][] = Ssc_Auto($hm5, 5);//算前三
    $hms5['three'][] = Ssc_Auto($hm5, 6);//算中三
    $hms5['three'][] = Ssc_Auto($hm5, 7);//算后三
    $hms5['niuniu'][] = $niuniu1;//牛牛
    $hms5['niuniu'][] = b5_niuds($niuniu1);//牛大
    $hms5['niuniu'][] = b5_niudx($niuniu1);//牛小

    $sql = "select order_num,order_sub_num,quick_type,number,win,status,is_win from order_lottery_sub WHERE order_num=ANY(select order_lottery.order_num from order_lottery WHERE lottery_number=$qishu_tj AND Gtype='TJ') AND status=0";
    $res5 = $mysql->getRows($sql);

    //定义数组存放对应彩种的子订单
    $arr1 = array();
    //定义数组存放对应的开奖结果
    $zjresultall = array();
    foreach ($res5 as $k => $v) {
        $arr1[] = $v['order_sub_num'];
        if ($v['quick_type'] == "第一球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm5[0]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm5[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm5[0])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第二球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm5[1]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm5[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm5[1])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第三球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm5[2]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm5[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm5[2])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第四球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm5[3]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm5[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm5[3])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "第五球") {
            if (in_array($v['number'], $num)) {
                if ($v['number'] == $hm5[4]) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $dx)) {
                if ($v['number'] == Ssc_Dx($hm5[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
            if (in_array($v['number'], $ds)) {
                if ($v['number'] == Ssc_Ds($hm5[4])) {
                    $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                    array_push($zjresultall, $array);
                }
            }
        }
        if ($v['quick_type'] == "总和龙虎和") {
            if (in_array($v['number'], $hms5['zh'])) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "前三") {
            if ($v['number'] == $hms5['three'][0]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "中三") {
            if ($v['number'] == $hms5['three'][1]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "后三") {
            if ($v['number'] == $hms5['three'][2]) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
        if ($v['quick_type'] == "牛牛") {
            if (in_array($v['number'], $hms5['niuniu'])) {
                $array = array("win" => $v['win'], "order_sub_num" => $v['order_sub_num'], "order_num" => $v['order_num']);
                array_push($zjresultall, $array);
            }
        }
    }
    //函数移除数组中的重复的值，并返回结果数组,再拼接成字符串
    $arr2 = implode(',', array_unique($arr1));

    //判断中奖数组存在且不为空的时候
    if (isset($zjresultall) && !empty($zjresultall)) {

        foreach ($zjresultall as $k => $v) {
            $win = 0.0;
            $set = array('is_win' => 1, 'status' => 1);
            $mysql->updateRows_me('order_lottery_sub', $set, "order_num='$v[order_num]' AND order_sub_num='$v[order_sub_num]'");
            $win = (float)$v['win'];

            $sql_money = "update user_list set money=money+$win WHERE user_id=(SELECT user_id FROM order_lottery WHERE order_num=$v[order_num])";
            $mysql->query($sql_money);
        }
    }
    //将子订单表中状态未结算修改为正常
    $sql = "update order_lottery_sub set status='1',is_win='0' WHERE status='0'AND order_sub_num IN ($arr2)";
    $mysql->query($sql);

    //将总订单表中状态未结算修改为正常
    $sql = "update order_lottery set status='1' WHERE status='0' AND lottery_number=$qishu_tj";
    $mysql->query($sql);

    //将时时彩结果表状态修改为正常
    $sql = "update lottery_result_tj set state='1' WHERE state='0' AND qishu=$qishu_tj";
    $mysql->query($sql);
}

